// pages/leixingfour/leixingfour.js
Page({
  /**
   * 页面的初始数据
   */
  data: {
    arr:[
     {index:'0',
     xiangmu:'事业单位'} ,{ index:'1',
     xiangmu:'教师招聘'},{index:'2',
     xiangmu:'三支一扶'},{index:'3',
     xiangmu:'医疗卫生'},{index:'4',
     xiangmu:'银行招聘'},{index:'5',
     xiangmu:'国企招聘'},{index:'6',
     xiangmu:'国家公务员'},{index:'7',
     xiangmu:'山东公务员'},{index:'8',
     xiangmu:'其他'}  
    ]
  },
  // 事件处理函数
  selectXiangmu: function (e) {
    var that = this;
    console.log(e)
    console.log(e.target.dataset.key)
    that.setData({
      theIndex: e.target.dataset.key,
      xiangmuming:that.data.arr[e.target.dataset.key].xiangmu
    })

  },
  next(){
    var that=this;
   if(that.data.theIndex==undefined)
   {
    wx.showToast({
      title: '请选择正在备考的项目',
      icon: 'none',
      duration: 2000 //持续的时间
    })
   }
   else{
    wx.request({ //发送请求
      url: 'https://zg99.offcn.com/index/biaodan/register?actid=40245&callback=?', //接收url
      level:1,
      data: {
        phone: that.data.phone,
        xiangmuname:that.data.xiangmuming,
        geneal: that.data.geneal,
        fenxiao: that.data.area,    
      }, //接收参数
      success(res) {
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        }
        console.log(theJson)
        wx.showToast({
          title: '提交成功',
          icon: 'none',
          duration: 2000 //持续的时间
        })
      }
    });
   }

  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    console.log(options);
    that.setData({
      area: options.area,
      geneal: options.agent,
      page: options.page,
    })
    if (options.p_open_id) {
      console.log('分享')
      that.setData({
        p_open_id: options.p_open_id
      })
    } else {
      console.log('no分享')
    }
    var phone = wx.getStorageSync('phone')
    that.setData({
      phone:phone
    })
    console.log(that.data.phone)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})